package com.sojson.project.controller.param.verify;

import java.sql.SQLException;

import com.sojson.project.entity.po.Comment;
import com.sojson.result.Result;
import com.sojson.util.StringUtil;

/**
 * 评论表参数验证
 * 
 * @author liu
 * @date 2021-03-16
 */
public class CommentParamVerify {

    /**
     * 单条插入
     * 
     * @param comment
     * @return
     * @throws SQLException
     */
    public static Result<?> insert(Comment comment) {
        if (StringUtil.isBlank(comment.getOrderId())) {
            return Result.fail("订单ID不能为空！");
        }
        Float starNum = comment.getStarNum();
        if (StringUtil.isBlank(starNum)) {
            return Result.fail("星级不能为空！");
        }
        if (starNum % 0.5F != 0) {
            return Result.fail("星级必须是0.5的倍数！");
        }
        if (starNum < 0.5 || starNum > 5) {
            return Result.fail("星级范围0.5-5！");
        }
        if (StringUtil.isBlank(comment.getContent())) {
            comment.setContent("此用户没有填写评价！");
        }
        String images = comment.getImages();
        if (StringUtil.isNotBlank(images) && comment.getImages().split(",").length > 3) {
            return Result.fail("图片最多只能有3张！");
        }

        return Result.success();
    }

    /**
     * 审核评论信息
     * 
     * @param comment
     * @return
     * @throws SQLException
     */
    public static Result<?> audit(Comment comment) {
        if (StringUtil.isBlank(comment.getId())) {
            return Result.fail("ID不能为空！");
        }
        if (StringUtil.isBlank(comment.getStatus())) {
            return Result.fail("审核状态不能为空！");
        }

        return Result.success();
    }

}